package com.lemon.smartsafetynew.ui.adapter.highDanger;

import android.graphics.drawable.AnimationDrawable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafetynew.entity.highDanger.HighDangerItemVo;
import com.lemon.smartsafetynew.util.common.CommonUtil;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import kale.adapter.LemonRcvAdapter;
import kale.adapter.item.AdapterItem;

/**
 * Created by Andrew on 2018/3/17.
 */

public class HighDangerItemAdapter extends LemonRcvAdapter<HighDangerItemVo> {

    public HighDangerItemAdapter(@Nullable List<HighDangerItemVo> data) {
        super(data);
    }

    @NonNull
    @Override
    public AdapterItem createItem(Object type) {
        return new ItemAdapter();
    }

    public class ItemAdapter implements AdapterItem<HighDangerItemVo> {

        @Bind(R.id.icon)
        ImageView icon;
        @Bind(R.id.name_tv)
        TextView nameTv;
        @Bind(R.id.thing_tv)
        TextView thingTv;
        @Bind(R.id.temperature_tv)
        TextView temperatureTv;
        @Bind(R.id.pressure_tv)
        TextView pressureTv;
        @Bind(R.id.num_tv)
        TextView numTv;
        @Bind(R.id.deviceID)
        TextView deviceID;

        @Override
        public int getLayoutResId() {
            return R.layout.item_high_danger_recycler_item;
        }

        @Override
        public void bindViews(View root) {
            ButterKnife.bind(this, root);
        }

        @Override
        public void setViews() {

        }

        @Override
        public void handleData(HighDangerItemVo highDangerItemVo, int position) {

            icon.setBackgroundResource(R.drawable.high_danger_animation);
            AnimationDrawable _animaition = (AnimationDrawable) icon.getBackground();
            _animaition.setOneShot(false);
            _animaition.start();//启动
            nameTv.setText("名称：" + CommonUtil.avoidNullString(highDangerItemVo.getName()));
            thingTv.setText("物质：" + CommonUtil.avoidNullString(highDangerItemVo.getThing()));
            temperatureTv.setText("温度：" + CommonUtil.avoidNullString(highDangerItemVo.getTemperature()));
            pressureTv.setText("压力：" + CommonUtil.avoidNullString(highDangerItemVo.getPressure()));
        }
    }
}
